<template>
  <div class="container" :style="'height: '+docheight+'px'">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">用户列表({{ total }})</div>
          <div class="tableCont">
            <div class="tableSerchCont">
              <div class="serchItem">
                <el-select v-model="order_status" placeholder="请选择会员状态">
                    <el-option
                        v-for="(item,index) in navArr"
                        :key="index"
                        :label="item.val"
                        :value="item.id">
                    </el-option>
                </el-select>
              </div>
              <div class="serchItem">
                <el-select v-model="is_child_photo" placeholder="请选择是否有照片">
                    <el-option
                        v-for="(item,index) in isPhotoArr"
                        :key="index"
                        :label="item.val"
                        :value="item.id">
                    </el-option>
                </el-select>
              </div>
              
              <div class="serchItem" style="width: 250px;">
                <el-input v-model="serchVal" placeholder="请输入相亲编号｜联系电话"></el-input>
              </div>
              <div class="headBtn">
                <btn value="搜索" @click="serchFn"></btn>
              </div>
            </div>
            <el-table
              :data="tableData"
              style="width: 100%">
              <el-table-column
                prop="dating_number"
                width="140"
                show-overflow-tooltip
                label="相亲编号"
              >
              </el-table-column>
              <el-table-column
                prop="nick_name"
                show-overflow-tooltip
                label="用户昵称"
              >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                label="孩子照片"
              >
              <template slot-scope="scope">
                    <bigImg v-if="scope.row.child_photo" height="40px" :src="scope.row.child_photo"></bigImg>
                  </template>
              </el-table-column>
              <el-table-column
                label="家长姓名"
              >
                <template slot-scope="scope">
                  <div>{{ scope.row.call_name }}家长</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="contact_mobile"
                width="140"
                label="家长电话"
              >
              </el-table-column>
              <el-table-column
                prop="xf_money"
                label="消费金额"
              >
              </el-table-column>
              <el-table-column
                prop="gold_coins"
                label="账号金币"
              >
              </el-table-column>
              <el-table-column
                prop="qx_cs"
                label="会员身份"
              >
                <template slot-scope="scope">
                  <div class="ctrolBtn">
                    <div v-if="scope.row.is_member==1">非会员</div>
                    <div class="greenBtn" v-if="scope.row.is_member==2">诚意会员</div>
                  </div>
                </template>
              
              </el-table-column>
              <el-table-column
                prop="qx_cs"
                label="账号状态"
              >
                <template slot-scope="scope">
                  <div class="ctrolBtn">
                    <div class="greenBtn" v-if="scope.row.user_status==1">正常</div>
                    <div class="redBtn" v-if="scope.row.user_status==2">限流</div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                width="300"
                  label="操作">
                  <template slot-scope="scope">
                    <div class="ctrolBtn">
                      <div class="text_btn redBtn" v-if="scope.row.user_status==1" @click="clearImg(scope.row)">清照片</div>
                      <div class="text_btn redBtn" v-if="scope.row.user_status==1" @click="checkStatus(scope.row)">限流</div>
                      <div class="text_btn blueBtn" v-if="scope.row.user_status==2" @click="checkStatus(scope.row)">恢复</div>
                      <div class="text_btn greenBtn" @click="toDetail(scope.row)">查看</div>
                      <div class="text_btn greenBtn" @click="toOrder(scope.row)">流水</div>
                      <div class="text_btn blueBtn" @click="copyFn(scope.row)">复制资料</div>
                    </div>
                  </template>
                </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                :current-page="page"
                @current-change="pageFn"
                :total="total">
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import leftcont from '@/components/leftCont.vue'
  import topcont from '@/components/topCont.vue'
  import bigImg from '@/components/public/bigImg.vue'
  import btn from '@/components/public/btn.vue'
  import {User,userStatus,clearPhoto,userDetails} from "@/http/api"

  export default {
    components: {bigImg,leftcont,topcont,btn},
    data() {
      return {
        serchVal:'',
        navArr:[
          {val:'全部',id:''},
          {val:'诚意会员',id:1},
        ],
        order_status:'',
        isPhotoArr:[
          {val:'全部',id:''},
          {val:'有照片',id:1},
          {val:'无照片',id:2},
        ],
        is_child_photo:'',
        tableData:[],
        page:1,
        per_page:5,
        total:0,
      }
    },
    props: {},
    methods:{
      copyFn(item){
        var data ={
          user_id:item.user_id,
        }
        userDetails(data).then((res)=>{
          if(res.data.code==1){
            let resData = res.data.data
            let cont1 = (resData.child_sex==1?'男':'女')+' · '+resData.child_birth_date+'年;'
            let cont2 = '身高：'+resData.child_height+'cm;体重：'+resData.child_weight+'kg;'
            let cont3 = '学历：'+resData.child_education+';职位：'+resData.child_career+';收入：'+resData.child_salary_start+'~'+resData.child_salary_end+';'
            let cont4 = '房产：'+resData.is_room+';车辆：'+resData.is_car+';'
            let cont5 = '所在地：'+resData.child_address
            let cont6 = '；全国相亲资源，全国各地都有，v搜《亲家来咯》;'
            let cont7 = '相亲说明：'+resData.dating_describe
            let copyVal = cont1 + cont2 + cont3 + cont4+cont5+cont6+cont7
            let oInput = document.createElement('input');
            oInput.value = copyVal;
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象;
            document.execCommand("Copy"); // 执行浏览器复制命令
            this.$message({
              type: 'success',
              message: '复制成功'
            });
            oInput.remove()
          }else{
            this.$message(res.data.msg)
          }
        }).catch((err)=>{
          this.$message('服务器请求超时');
        })
      },
      pageFn(index){
        this.page = index
        this.showBottom()
      },
      checkStatus(item){//saveManul
        let str = item.user_status==1?'限流':'恢复'
        this.$confirm('确定'+str+'此用户吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let data ={
              user_id:item.user_id,
              user_status:item.user_status==1?2:1
            }
            const loading = this.$loading({
              lock: true,
              text: 'Loading',
              spinner: 'el-icon-loading',
              background: 'rgba(255, 255, 255, 0.7)'
            });
            userStatus(data).then((res)=>{
              if(res.data.code==1){//更改状态成功
                this.$message({
                  type: 'success',
                  message: res.data.msg
                });

                this.showBottom()
              }else{
                this.$message(res.data.msg)
              }
              loading.close()
            }).catch((err)=>{
              loading.close()
              this.$message('服务器请求超时');
            })
          })
      },
      clearImg(item){
        this.$confirm('确定清除此用户孩子照片吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let data ={
              user_id:item.user_id,
            }
            const loading = this.$loading({
              lock: true,
              text: 'Loading',
              spinner: 'el-icon-loading',
              background: 'rgba(255, 255, 255, 0.7)'
            });
            clearPhoto(data).then((res)=>{
              if(res.data.code==1){
                this.$message({
                  type: 'success',
                  message: res.data.msg
                });
                this.showBottom()
              }else{
                this.$message(res.data.msg)
              }
              loading.close()
            }).catch((err)=>{
              loading.close()
              this.$message('服务器请求超时');
            })
          })
      },
      serchFn(){ 
        this.page = 1
        this.total = 0
        this.showBottom()
      },
      showBottom(){//showBottom
        var data ={
          search:this.serchVal,
          page:this.page,
          per_page:this.per_page,
          is_child_photo:this.is_child_photo,
        }
        User(data).then((res)=>{
          if(res.data.code==1){
            this.tableData = res.data.data.data //把最新的数组赋值给tableData
            this.total = res.data.data.total
          }else{
            this.$message(res.data.msg)
          }
        }).catch((err)=>{
          this.$message('服务器请求超时');
        })
      },
      toOrder(item){
        this.$router.push({path:'/userCenterOrder',query:{id:item.user_id}})
      },
      toDetail(item){
        this.$router.push({path:'/userCenterInfoDetail',query:{id:item.user_id}})
      },
    },
    mounted(){
    },
    created() {
      this.showBottom()
    },
  }
</script>

<style scoped lang="less">
  .container{
    width: 100%;
    display: flex;
    overflow: hidden;
    .righCont{
      display: flex;
      flex-direction: column;
      flex: 1;
      margin-left: 15px;
      height: 100%;
      width: 10px;
      background-color: #F4F8FF;
      .content{
        padding: 20px;
        box-sizing: border-box;
        width: 100%;
        flex: 1;
        overflow: auto;
        .payTable{
          margin-top: 20px;
          width: 100%;
          background-color: #fff;
          padding: 15px;
          box-sizing: border-box;
          .trendTop{
            font-weight: bold;
            font-size: 16px;
            cursor: pointer;
          }
          .tableCont{
            width: 100%;
            margin-top: 15px;
            .redBtn{
                color: #F56C6C;
              }
              .blueBtn{
                color: #96A1FE;
              }
              .greenBtn{
                color: #85CE61;
              }
              .blackBtn{
                color: #666;
              }
            .tableSerchCont{
              width: 100%;
              display: flex;
              justify-content: flex-end;
              margin-bottom: 10px;
              .serchItem{
                width: 150px;
                margin-left: 10px;
              }
              .headBtn{
                margin-left: 10px;
              }
            }
            .ctrolBtn{
              display: flex;
              .text_btn{
                margin: 0 5px;
                cursor: pointer;
                font-size: 14px;
              }
              

            }
            .pageCont{
              padding: 30px 0;
              display: flex;
              justify-content: center;
            }
          }
        }
      }
    }
  }
</style>
